package com.ttx.pattern.example.builder.variant;

/**
 * @author TimFruit
 * @date 2019/7/2 14:58
 */

public class Person {
    
    private final String name; // 由于定义了不可变类型final
    private final int age;
    private final int height;
    private final String address;

    public Person(Builder builder) {
        this.name=builder.name;
        this.age=builder.age;
        this.height=builder.height;
        this.address=builder.address;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public int getHeight() {
        return height;
    }

    public String getAddress() {
        return address;
    }

    public static class Builder{
        private final String name;
        private int age;
        private int height;
        private String address;

        public Builder(String name) {
            this.name = name;
        }

        public Builder setAge(int age) {
            this.age = age;
            return this;
        }

        public Builder setHeight(int height) {
            this.height = height;
            return this;
        }

        public Builder setAddress(String address) {
            this.address = address;
            return this;
        }
        
        public Person build(){
            return new Person(this);
        }
    }
}
